package LeetCode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}18:41
 */
public class LeetCode139 {
    public boolean wordBreak(String s, List<String> wordDict) {
        if (s.equals("")){
            return true;
        }
        // 不去重的情况
        boolean[] dp = new boolean[s.length() + 1];
        Set<String> set = new HashSet<>(wordDict);
        dp[0] = true;
        for (int i = 1; i <= s.length(); i++){
            for (int j = 0; j < i;j++){
                if (dp[j] && wordDict.contains(s.substring(j,i))){
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[s.length()];
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("Leet");
        list.add("Code");
        System.out.println(new LeetCode139().wordBreak("LeetCode", list));
    }
}
